package com.gc.baselib.utils;

import android.app.ActivityManager;
import android.content.Context;
import android.os.Looper;

/**
 * @author admin
 * @Date 2022/6/9 22:49
 * @package： com.zk.baselib.utils
 * @decrpition
 */
public class SysUtils {
    /**
     * 判断当前进程是否为主进程
     */
    public static boolean isMainProcess(Context context) {
        int pid = android.os.Process.myPid();
        ActivityManager activityManager = (ActivityManager)context. getSystemService(Context.ACTIVITY_SERVICE);
        for (ActivityManager.RunningAppProcessInfo appProcess : activityManager.getRunningAppProcesses()) {
            if (appProcess.pid == pid) {
                return context.getApplicationInfo().packageName.equals(appProcess.processName);
            }
        }
        return false;
    }

    /**
     * 是判断当前线程否为主线程
     */
    public static boolean isMainThread() {
        return Looper.getMainLooper() == Looper.myLooper();
    }
}
